package arsmodeller;

import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

import arsmodeller.editors.MyEditorInput;
import arsmodeller.editors.MyGraphicalEditor;

/**
 * This workbench advisor creates the window advisor, and specifies the
 * perspective id for the initial window.
 */
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {

	public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
			IWorkbenchWindowConfigurer configurer) {
		return new ApplicationWorkbenchWindowAdvisor(configurer);
	}

	@Override
	@SuppressWarnings({ "deprecation" })
	public void preWindowOpen(IWorkbenchWindowConfigurer configurer) {
		super.preWindowOpen(configurer);

	}

	public String getInitialWindowPerspectiveId() {
		return "arsmodeller.perspectives.Perspective";
	};

	@Override
	public void postStartup() {
		try {

			Display.getDefault().asyncExec(new Runnable() {
				@Override
				public void run() {

					IWorkbenchWindow iw = PlatformUI.getWorkbench()
							.getActiveWorkbenchWindow();
					IWorkbenchPage page = iw.getActivePage();
					try {
						page.openEditor(new MyEditorInput("ARSModeller"),
								MyGraphicalEditor.ID, false);
					} catch (PartInitException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

				}
			});

		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
